{{- if .Values.global.modules.publicDomainTemplate }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    web.deckhouse.io/export-name: "dashboard"
    web.deckhouse.io/export-icon: "/public/img/dashboard.png"
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
    nginx.ingress.kubernetes.io/affinity: cookie
    nginx.ingress.kubernetes.io/affinity-mode: persistent
    nginx.ingress.kubernetes.io/session-cookie-name: d8-dashboard-affinity
{{- if and (ne (include "helm_lib_module_https_mode" .) "Disabled") .Values.dashboard.auth.externalAuthentication }}
    nginx.ingress.kubernetes.io/auth-signin: {{ .Values.dashboard.auth.externalAuthentication.authSignInURL | quote }}
    nginx.ingress.kubernetes.io/auth-url: {{ .Values.dashboard.auth.externalAuthentication.authURL | quote }}
 {{- if .Values.dashboard.auth.externalAuthentication.useBearerTokens }}
    nginx.ingress.kubernetes.io/auth-response-headers: "authorization"
 {{- end }}
    nginx.ingress.kubernetes.io/proxy-buffer-size: 32k
{{- else }}

    nginx.ingress.kubernetes.io/auth-type: basic
    nginx.ingress.kubernetes.io/auth-secret: basic-auth
    nginx.ingress.kubernetes.io/auth-realm: "Authentication Required"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_ssl_certificate /etc/nginx/ssl/client.crt;
      proxy_ssl_certificate_key /etc/nginx/ssl/client.key;
      proxy_ssl_protocols TLSv1.2;
      proxy_ssl_session_reuse on;
{{- end }}
{{- if .Values.dashboard.auth.whitelistSourceRanges }}
    nginx.ingress.kubernetes.io/whitelist-source-range: {{ .Values.dashboard.auth.whitelistSourceRanges | join "," }}
{{- end }}
  name: dashboard
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "dashboard")) | nindent 2 }}
spec:
  ingressClassName: {{ include "helm_lib_module_ingress_class" . | quote }}
  rules:
  - host: {{ include "helm_lib_module_public_domain" (list . "dashboard") }}
    http:
      paths:
      - backend:
          service:
            name: dashboard
            port:
              name: https
        path: /
        pathType: ImplementationSpecific
  {{- if (include "helm_lib_module_https_ingress_tls_enabled" .) }}
  tls:
  - hosts:
      - {{ include "helm_lib_module_public_domain" (list . "dashboard") }}
    secretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls") }}
  {{- end }}
  {{- if eq (include "helm_lib_module_https_mode" .) "CertManager" }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: dashboard
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "dashboard")) | nindent 2 }}
spec:
  certificateOwnerRef: false
  secretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls") }}
  {{ include "helm_lib_module_generate_common_name" (list . "dashboard") | nindent 2 }}
  dnsNames:
  - {{ include "helm_lib_module_public_domain" (list . "dashboard") }}
  issuerRef:
    name: {{ include "helm_lib_module_https_cert_manager_cluster_issuer_name" . }}
    kind: ClusterIssuer
  {{- end }}
{{- end }}
